package com.egan.pet.admin.controller;

import com.egan.entity.dto.CategoryDTO;
import com.egan.entity.dto.ItemCatPageQueryDTO;
import com.egan.entity.po.ItemCat;
import com.egan.pet.admin.result.PageResult;
import com.egan.pet.admin.result.Result;
import com.egan.pet.admin.service.IItemCatService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * @author NoobMaster69  * @date 2024/9/19 0019 星期四 8:21
 */

@RestController
@RequestMapping("/category")
@Tag(name = "分类相关接口")
public class CategoryController {

    @Resource
    private IItemCatService itemCatService;

    @PostMapping
    @Operation(summary = "新增分类")
    public Result<String> save(@RequestBody CategoryDTO categoryDTO){
        itemCatService.saveCategory(categoryDTO);
        return Result.success();
    }

    @DeleteMapping
    @Operation(summary = "删除分类")
    public Result<String> deleteById(Long id){
        itemCatService.removeById(id);
        return Result.success();
    }

    @PutMapping
    @Operation(summary = "修改分类")
    public Result<String> update(@RequestBody CategoryDTO categoryDTO) {
        itemCatService.updateCategory(categoryDTO);
        return Result.success();
    }

    @PostMapping("/status/{status}")
    @Operation(summary = "启用禁用分类")
    public Result<String> statusOrStop(@PathVariable("status") Integer status, Long id) {
        itemCatService.statusOrStop(status,id);
        return Result.success();
    }

    @GetMapping("/list")
    @Operation(summary = "根据是否为父类查找分类")
    public Result<List<ItemCat>> list(Integer type) {
        List<ItemCat> list = itemCatService.listAll(type);
        return Result.success(list);
    }
    @PostMapping("/page")
    @Operation(summary = "分类分页查询")
    public Result<PageResult> page(@RequestBody ItemCatPageQueryDTO itemCatPageQueryDTO){
        PageResult pageResult = itemCatService.pageQuery(itemCatPageQueryDTO);
        return Result.success(pageResult);
    }
}
